// elsePage/pages/startBargain/startBargain.js
const util = require('../../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrl: getApp().globalData.imgUrl,
    imgUrls: getApp().globalData.imgUrls,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

    this.setData({
      options
    })
    var that = this;
    let {
      options: {
        goods_id,
        bargain_id
      }
    } = this.data
    util.API('bargain/v1.wxbargain/start_bargain', {
      goods_id,
      bargain_id
    }).then(({
      data,
      code,
      msg
    }) => {
      that.setData({
        info: data
      })
    });
    util.API('bargain/v1.wxbargain/get_address', {}).then(({
      data,
      code,
      msg
    }) => {
      that.setData({
        Address: data
      })
    })
    if (this.data.options.type == '0') {
      util.API('bargain/v1.wxbargain/bargain_to_bottom', {
        goods_id,
        bargain_id
      }).then(({
        data,
        code,
        msg
      }) => {
        // data.distribution_name = JSON.stringify(distribution_name)

        // data.low_goods_price = data.low_goods_price
        data.sku_type = JSON.parse(data.sku_type)
        data.sku = JSON.stringify(data.sku)

        // data.goods_cover = data.goods_cover.split(",");
        that.setData({
          data
        })
      })
    }

  },
  // jump() {
  //   wx.navigateTo({
  //     url: '/elsePage/pages/bargainDetails/bargainDetails',

  //   })
  // },
  myevent(e) {
    this.setData({
      showSpecification: e.detail.showSpecification
    })
  },
  preventTouchMove: function(event) {
    return false
  },
  showSpecification() {
    var that=this
    if (this.data.options.type == '0') {
      this.setData({
        showSpecification: !this.data.showSpecification
      })
    } else {
      if (!this.data.suo) {
          this.setData({
            suo: true
          })
    console.log('res')
        util.API('bargain/v1.wxbargain/bargain_info', {
          uniqueKey: '',
          address_id: this.data.Address.address_id,
          goods_id: this.data.options.goods_id,
          bargain_id: this.data.options.bargain_id,
        }).then(({
          data,
          code,
          msg
        }) => {
          console.log(data, code, msg)
          if (code == 200) {
           
            wx.redirectTo({
              url: `/elsePage/pages/bargainDetails/bargainDetails?one_moeny=${data.one_moeny}&bargain_people_id=${data.bargain_people_id}`,
            })
            setTimeout(function () {
              that.setData({
                suo: false
              })
            }, 1000)
          } else {
            wx.showToast({
              title: msg,

            })
          }
        })
      }
    
    }
  }

})